package inits

import (
	"context"
	"fmt"
	"github.com/go-redis/redis/v8"
	"log"
	"server/config"
)

var Ctx = context.Background()
var RedisDB *redis.Client

func InitRedis() {
	RedisConf := config.AppConf.Redis
	addr := fmt.Sprintf("%s:%d", RedisConf.Host, RedisConf.Port)
	RedisDB = redis.NewClient(&redis.Options{
		Addr:     addr,
		Password: RedisConf.Password, // no password set
		DB:       3,                  // use default DB
	})
	_, err := RedisDB.Ping(Ctx).Result()
	if err != nil {
		panic(err)
	}
	log.Println("redis init success")
}
